import router from './router'
import { userStore } from '@/pinia/modules/user'
import { getUrlParams } from "@/utils/public";
let getgetActInfoSet = false
router.beforeEach( async (to, from) => {
  const useUserStore = userStore();
  const queryString = getUrlParams("q")
  useUserStore.getPlatform()
  if(queryString) {
    const query = JSON.parse(atob(queryString) || `{ i_id:'', r_id:'' }`) || { i_id:'', r_id:'' }
    let {
      i_id = useUserStore.invite_code,
      r_id = useUserStore.room_id,
    } = query
    if(to.name == 'Home' && getgetActInfoSet == false) {
      getgetActInfoSet = true
      useUserStore.invite_code = i_id;
      useUserStore.room_id = r_id
      useUserStore.getPlatform()
      // await useUserStore.getSystemInfo()
    }
    return true
  } else {
    if(to.path!='/404') {
      return {
        path:'/404'
      }
    }
    return true
  }
})

router.afterEach((to) => {
  document.title = to.meta.title as string;
})
